package com.slofzx.nuoda.evaluation.param.controller;

import com.slofzx.nuoda.common.annotation.SysLog;
import com.slofzx.nuoda.evaluation.param.dto.CommonParamVersionDTO;
import com.slofzx.nuoda.evaluation.param.dto.CommonParamVersionDataDTO;
import com.slofzx.nuoda.evaluation.param.enums.ParamVersionStateEnum;
import com.slofzx.nuoda.evaluation.param.service.CommonParamVersionDataService;
import com.slofzx.nuoda.evaluation.param.vo.CommonParamVersionVO;
import com.slofzx.nuoda.evaluation.param.service.CommonParamVersionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.slofzx.nuoda.common.controller.BaseController;
import com.slofzx.nuoda.common.vo.AjaxResultVO;
import com.slofzx.nuoda.common.vo.PageResultVO;
import com.slofzx.nuoda.common.enums.ServiceResult;

import java.util.*;

/**
 * 公共参数版本信息控制层
 *
 * @author nuoda
 * @menu 公共参数版本信息
 * @since 2023-10-17 16:02:20
 */
@RestController
@RequestMapping("/settings/common_param_version")
public class CommonParamVersionController extends BaseController {
    /**
     * 服务对象
     */
    @Autowired
    private CommonParamVersionService commonParamVersionService;
    @Autowired
    private CommonParamVersionDataService commonParamVersionDataService;


    /**
     * 通过查询条件查询列表数据
     *
     * @param dto 查询参数
     * @return 列表数据
     */
    @GetMapping("/data")
    public AjaxResultVO<List<CommonParamVersionVO>> queryList(CommonParamVersionDTO dto) {
        List<CommonParamVersionVO> dataList = commonParamVersionService.queryList(dto);
        return PageResultVO.newSuccessResult(dataList, dto.getCount());
    }
    /**
     * 通过查询条件查询列表数据
     *
     * @param dto 查询参数
     * @return 列表数据
     */
    @GetMapping("/queryPublish")
    public AjaxResultVO<List<CommonParamVersionVO>> queryPublish(CommonParamVersionDTO dto) {
        dto.setState(ParamVersionStateEnum.PUBLISH.getId());
        List<CommonParamVersionVO> dataList = commonParamVersionService.queryList(dto);
        return PageResultVO.newSuccessResult(dataList, dto.getCount());
    }

    /**
     * 复制数据
     *
     * @param dto 参数数据
     * @return 操作结果
     */
    @ResponseBody
    @PostMapping(value = "/copy")
    public AjaxResultVO copy(@RequestBody CommonParamVersionDTO dto) {
        ServiceResult resultEnum = commonParamVersionService.copy(dto);
        return AjaxResultVO.getInstance(resultEnum);
    }
    /**
     * 创建数据
     *
     * @param dto 参数数据
     * @return 操作结果
     */
    @ResponseBody
    @PostMapping(value = "/create")
    public AjaxResultVO create(@RequestBody CommonParamVersionDTO dto) {
        ServiceResult resultEnum = commonParamVersionService.create(dto);
        return AjaxResultVO.getInstance(resultEnum);
    }

    /**
     * 数据更新
     *
     * @param dto
     * @return 操作结果
     */
    @ResponseBody
    @PostMapping(value = "/update")
    public AjaxResultVO update(@RequestBody CommonParamVersionDTO dto) {
        ServiceResult resultEnum = commonParamVersionService.update(dto);
        return AjaxResultVO.getInstance(resultEnum);
    }

    /**
     * 删除数据
     *
     * @param id
     * @return 操作结果
     */
    @ResponseBody
    @PostMapping(value = "/delete")
    @RequiresPermissions("common_param:delete")
    public AjaxResultVO delete(@RequestParam String id) {
        ServiceResult resultEnum = commonParamVersionService.deleteById(id);
        return AjaxResultVO.getInstance(resultEnum);
    }

    /**
     * 查询单个数据
     *
     * @return id对应数据
     */
    @ResponseBody
    @GetMapping(value = "/info/{id}")
    public AjaxResultVO<CommonParamVersionVO> queryById(@PathVariable String id) {
        CommonParamVersionVO vo = commonParamVersionService.queryById(id);
        return AjaxResultVO.newSuccessResult(vo);
    }

    @SysLog(title = "公共参数版本发布",group = "公共参数")
    @RequiresPermissions("common_param:record")
    @ResponseBody
    @PostMapping(value = "/publish")
    public AjaxResultVO publish(@RequestBody CommonParamVersionDTO dto) {
        ServiceResult resultEnum = commonParamVersionService.publish(dto);
        return AjaxResultVO.getInstance(resultEnum);
    }

    /**
     * 取消发布数据
     *
     * @param dto 参数数据
     * @return 操作结果
     */
    @SysLog(title = "公共参数取消版本发布",group = "公共参数")
    @RequiresPermissions("common_param:record")
    @ResponseBody
    @PostMapping(value = "/unPublish")
    public AjaxResultVO unPublish(@RequestBody CommonParamVersionDTO dto) {
        ServiceResult resultEnum = commonParamVersionService.unPublish(dto);
        return AjaxResultVO.getInstance(resultEnum);
    }

    @SysLog(title = "公共参数版本数据更新",group = "公共参数")
    @RequiresPermissions("common_param:record")
    @ResponseBody
    @PostMapping(value = "/data/save")
    public AjaxResultVO saveDetailData(@RequestBody CommonParamVersionDataDTO dto) {
        ServiceResult resultEnum = commonParamVersionDataService.save(dto);
        return AjaxResultVO.getInstance(resultEnum);
    }

}
